package cn.crc.pjblog.components;

import java.util.Calendar;


import org.apache.tapestry5.MarkupWriter;

import org.apache.tapestry5.annotations.Persist;


/**
 * @author doublel
 * Blog显示的日历控件
 * */
public class BlogCalendar {
	

//	传入的年
	@Persist("flash")
//	@Parameter
	private int Cyear;
//	传入的月
	@Persist("flash")
//	@Parameter
	private int Cmonth;
//	传入的日
	@Persist("flash")
//	@Parameter
	private int Cday;
	
	@Persist("flash")
	private int py;
	@Persist("flash")
	private int pm;
	@Persist("flash")
	private int ny;
	@Persist("flash")
	private int nm;
	
	private String curDate;
	private Calendar cd;
	
	/**
	 *初始化参数为当前日期 
	 *
	 * */
	public void setupRender(MarkupWriter writer){
		
		cd = Calendar.getInstance();
		
		 	
		
		
//		writer.writeRaw("<div id=\"Side_Calendar\" class=\"sidepanel\">");
//		writer.writeRaw("<h4 class=\"Ptitle\">Calendar</h4>");
//		writer.writeRaw("<div class=\"Pcontent\">");
//		writer.writeRaw("<div id=\"Calendar_Body\">");
//		writer.writeRaw("<div id=\"Calendar_Top\">");
//		writer.writeRaw("<div id=\"LeftB\"" +
//				"default.asp?log_Year=2007&amp;log_Month=6'\"></div>");
//		writer.writeRaw("<div id=\"RightB\""+
//				"onclick=\"location.href='default.asp?log_Year=2007&amp;log_Month=8'\"></div>"+
//				String.valueOf(this.Cyear)+"年"+ String.valueOf(this.Cmonth)+"月"+String.valueOf(this.Cday)+"日</div>");	
//		writer.writeRaw("<div id=\"Calendar_week\"><ul class=\"Week_UL\">" +
//				"<li><font color=\"#FF0000\">日</font></li><li>一</li><li>二</li><li>三</li><li>四</li><li>五</li><li>六</li></ul></div>");
				

	    
		writer.writeRaw("<div class=\"Calendar_Day\">");
//		writer.write("输出成功");
		if (this.Cyear == 0){

			this.Cyear = cd.get(Calendar.YEAR);
			this.Cmonth = cd.get(Calendar.MONTH)+1;
			this.Cday = cd.get(Calendar.DAY_OF_MONTH);

		}

		this.curDate = String.valueOf(this.Cyear)+"年"+String.valueOf(this.Cmonth)+"月";
		
		this.pm = this.Cmonth -1;
		if (this.pm<1){
			this.pm = 12;
			this.py = this.Cyear -1;
		}else
		{
			this.py = this.Cyear;
		}
		this.nm= this.Cmonth+1;
		if (this.nm>12){
			this.nm = 1;
			this.ny = this.Cyear+1;
		}
		else{
			this.ny = this.Cyear;
		}

		
		
	}
	public void afterRender(MarkupWriter writer){
		
		writer.writeRaw("</div>");
		
	}
	
	public void cleanupRender(MarkupWriter writer){
		

		
	}
	
	/**
	 * 前一个月链接
	 * 
	 * */
	public void onActionFromleftB(){

		this.Cyear = this.getPy();
		this.Cmonth = this.getPm();
		
	}
	/**
	 * 后一个月链接
	 * */
	public void onActionFromrightB(){
		
		this.Cyear = this.getNy();
		this.Cmonth = this.getNm();

	}
	
	/* (non-Javadoc)
	 * @see org.apache.tapestry.corelib.base.AbstractField#processSubmission(org.apache.tapestry.services.FormSupport, java.lang.String)
	 */
//	@Override
//	protected void processSubmission(FormSupport formSupport, String elementName) {
//		// TODO Auto-generated method stub
//		System.out.println("this.rightB11.py="+this.getPy());
//		System.out.println("this.rightB11.pm="+this.getPm());
//		System.out.println("this.rightB11.py="+this.getPy());
//		System.out.println("this.rightB11.pm="+this.getPm());
//	}

	/**
	 * @return the cday
	 */
	public int getCday() {
		return Cday;
	}


	/**
	 * @return the cmonth
	 */
	public int getCmonth() {
		return Cmonth;
	}


	/**
	 * @return the cyear
	 */
	public int getCyear() {
		return Cyear;
	}


	/**
	 * @param cday the cday to set
	 */
	public void setCday(int cday) {
		Cday = cday;
	}


	/**
	 * @param cmonth the cmonth to set
	 */
	public void setCmonth(int cmonth) {
		Cmonth = cmonth;
	}


	/**
	 * @param cyear the cyear to set
	 */
	public void setCyear(int cyear) {
		Cyear = cyear;
	}

	/**
	 * @return the curDate
	 */
	public String getCurDate() {
		return curDate;
	}

	/**
	 * @return the nm
	 */
	public int getNm() {
		return nm;
	}

	/**
	 * @return the ny
	 */
	public int getNy() {
		return ny;
	}

	/**
	 * @return the pm
	 */
	public int getPm() {
		return pm;
	}

	/**
	 * @return the py
	 */
	public int getPy() {
		return py;
	}

	/**
	 * @param curDate the curDate to set
	 */
	public void setCurDate(String curDate) {
		this.curDate = curDate;
	}

	/**
	 * @param nm the nm to set
	 */
	public void setNm(int nm) {
		this.nm = nm;
	}

	/**
	 * @param ny the ny to set
	 */
	public void setNy(int ny) {
		this.ny = ny;
	}

	/**
	 * @param pm the pm to set
	 */
	public void setPm(int pm) {
		this.pm = pm;
	}

	/**
	 * @param py the py to set
	 */
	public void setPy(int py) {
		this.py = py;
	}
	
}
